import { getAreaObj } from '@/utils/util'

export const orderStatusArr = [
	{
		label: '待付款',
		value: '0',
	},
	{
		label: '待接单',
		value: '1',
	},
	{
		label: '已接单',
		value: '2',
	},
	{
		label: '接单人取消',
		value: '3',
	},
	{
		label: '下单人取消',
		value: '4',
	},
	{
		label: '服务开始',
		value: '5',
	},
	{
		label: '服务结束',
		value: '6',
	},
	{
		label: '服务对象已评价',
		value: '7',
	},
	{
		label: '服务员已评价',
		value: '8',
	},
	{
		label: '工单已回访',
		value: '9',
	},
]

export const detailConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [
		{
			label: '工单编号',
			prop: 'orderNo',
			span: 8,
		},
		{
			label: '订单状态',
			prop: 'orderStatus',
			type: 'select',
			dicData: orderStatusArr,
			span: 8,
		},
		{
			label: '工单有效性',
			prop: 'effectiveStatus',
			type: 'select',
			dicData: [
				{ label: '正常', value: 0, type: 'success' },
				{ label: '异常', value: 1, type: 'danger' },
				{ label: '未校验', value: 2, type: 'warning' },
			],
			span: 8,
		},
		{
			label: '异常原因',
			prop: 'errorInfo',
			span: 8,
		},
		{
			label: '服务对象姓名',
			prop: 'elderlyName',
			span: 8,
		},
		{
			label: '联系方式',
			prop: 'elderlyPhone',
			span: 8,
		},
		{
			label: '服务对象身份证号',
			prop: 'elderlyIdCard',
			span: 8,
		},
		{
			label: '服务开始时间',
			prop: 'startTime',
			span: 8,
		},
		{
			label: '服务结束时间',
			prop: 'endTime',
			span: 8,
		},
		{
			label: '详细地址',
			prop: 'address',
			span: 8,
		},
		{
			label: '服务员姓名',
			prop: 'staffName',
			span: 8,
		},
		{
			label: '服务员联系方式',
			prop: 'staffPhone',
			span: 8,
		},
		{
			label: '服务组织机构',
			prop: 'organizationName',
			span: 8,
		},
		{
			label: '备注',
			prop: 'organizationName',
			span: 24,
		},
		{
			type: 'DividerHtml',
			labelPosition: 'top',
			position: 'center',
			modelValue: '操作记录',
			span: 24,
		},
		{
			prop: 'operateLog',
			span: 24,
		},
		{
			type: 'DividerHtml',
			labelPosition: 'top',
			position: 'center',
			modelValue: '服务地图',
			span: 24,
		},
		{
			prop: 'serviceMap',
			span: 24,
		},
	],
}

export const detailServiceConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [
		{
			type: 'DividerHtml',
			labelPosition: 'top',
			position: 'center',
			modelValue: '服务项目',
			span: 24,
		},
		{
			custome: 'table',
			prop: 'orderItems',
			column: [
				{
					label: '服务照片',
					prop: 'logo',
					type: 'upload',
					showLabel: false,
					custome: 'file',
					span: 8,
				},
				{
					label: '服务项目',
					prop: 'name',
					type: 'text',
					showLabel: false,
					span: 8,
				},
				{
					label: '归属大类',
					prop: 'supName',
					type: 'input',
					span: 8,
					showLabel: false,
				},
				{
					label: '项目描述',
					prop: 'describe',
					type: 'input',
					span: 8,
					showLabel: false,
				},
				{
					label: '项目单价',
					prop: 'price',
					type: 'input',
					span: 8,
					showLabel: false,
				},
				{
					label: '项目次数',
					prop: 'num',
					type: 'input',
					span: 8,
					showLabel: false,
				},
				{
					label: '金额',
					prop: 'amount',
					type: 'input',
					span: 8,
					showLabel: false,
				},
			],
		},
		{
			type: 'DividerHtml',
			labelPosition: 'top',
			position: 'center',
			modelValue: '服务照片及录音',
			span: 24,
		},
		{
			label: '服务前服务照片及录音',
			prop: 'beforeServicePicStr',
			type: 'upload',
			showLabel: false,
			span: 24,
		},
		{
			prop: 'beforeServiceAudio',
			span: 24,
			type: 'upload',
		},
		{
			label: '服务中服务照片及录音',
			prop: 'middleServicePicStr',
			type: 'upload',
			showLabel: false,
			span: 24,
		},
		{
			prop: 'middleServiceAudio',
			span: 24,
			type: 'upload',
		},
		{
			label: '服务后服务照片及录音',
			prop: 'afterServicePicStr',
			type: 'upload',
			showLabel: false,
			span: 24,
		},
		{
			prop: 'afterServiceAudio',
			span: 24,
			type: 'upload',
		},
	],
}
export const detailCallBackConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '工单编号', prop: 'orderNo' },
		{
			label: '回访类型',
			prop: 'spotType',
			custome: 'PointStatus',
			dicData: [
				{
					label: '自动',
					value: 1,
				},
				{
					label: '人工',
					value: 2,
				},
			],
		},
		{
			label: '回访状态',
			prop: 'visitStatus',
			custome: 'PointStatus',
			dicData: [
				{
					label: '未回访',
					value: 0,
					color: '#E80000',
				},
				{
					label: '已回访',
					value: 1,
					color: '#00C92F',
				},
			],
		},
		{ label: '回访内容', prop: 'batchName' },
		{ label: '回访结果', prop: 'visitResultLabel' },
		{ label: '回访人/坐席', prop: 'updateUserName' },
		{ label: '回访时间', prop: 'updateTime' },
		{
			label: '操作',
			prop: 'menu',
			width: 200,
			fixed: 'right',
		},
	],
}
export const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	column: [
		{
			label: '所属地区',
			prop: 'areas',
			checkStrictly: true,
			type: 'AplidAreaSelect',
			span: 8,
		},
		{
			label: '工单编号',
			prop: 'orderNo',
			type: 'input',
			span: 8,
		},
		{
			label: '服务对象',
			prop: 'elderlyName',
			type: 'input',
			span: 8,
		},
		{
			label: '身份证号',
			prop: 'elderlyIdCard',
			type: 'input',
			span: 8,
		},
		{
			label: '订单状态',
			prop: 'orderStatus',
			type: 'select',
			dicData: orderStatusArr,
			span: 8,
		},
		{
			label: '服务组织单位',
			prop: 'organizationName',
			type: 'input',
			span: 8,
		},
		{
			label: '创建时间',
			prop: 'createTimeBetween',
			type: 'dateBetween',
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			span: 8,
		},
		{
			label: '服务员',
			prop: 'staffName',
			type: 'input',
			span: 8,
		},
		{
			label: '证件号码',
			prop: 'staffIdCard',
			type: 'input',
			span: 8,
		},
		{
			label: '工单有效性',
			prop: 'effectiveStatus',
			type: 'select',
			dicData: [
				{ label: '正常', value: 0 },
				{ label: '异常', value: 1 },
				{ label: '未校验', value: 2 },
			],
			span: 8,
		},
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '工单编号', prop: 'orderNo' },
		{ label: '开始时间', prop: 'startTime' },
		{ label: '结束时间', prop: 'endTime' },
		{ label: '服务组织单位', prop: 'organizationName' },
		{ label: '服务对象', prop: 'elderlyName' },
		{ label: '服务时长', prop: 'serviceLength' },
		{ label: '服务项目', prop: 'subItemNames' },
		{ label: '服务人员', prop: 'staffName' },
		{ label: '金额', prop: 'shouldAmount' },
		{
			label: '工单状态',
			prop: 'orderStatus',
			custome: 'tag',
			dicData: orderStatusArr,
		},
		{
			label: '工单有效性',
			prop: 'effectiveStatus',
			type: 'select',
			custome: 'tag',
			dicData: [
				{ label: '正常', value: 0, type: 'success' },
				{ label: '异常', value: 1, type: 'danger' },
				{ label: '未校验', value: 2, type: 'warning' },
			],
			span: 8,
		},
		{ label: '服务照片', prop: 'middleServicePicStr', custome: 'file' },
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

export const detailEvaluateConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	labelWidth: '120px',
	column: [
		{
			type: 'DividerHtml',
			labelPosition: 'top',
			position: 'center',
			modelValue: '老人服务评价',
			span: 24,
		},
		{
			label: '老人对本次服务内容的满意度',
			prop: 'serviceStar',
			custome: 'RateXing',
			span: 12,
		},
		{
			label: '老人对本次服务人员的满意度',
			prop: 'practitionersStar',
			span: 12,
			custome: 'RateXing',
		},
		{
			type: 'DividerHtml',
			labelPosition: 'top',
			position: 'center',
			modelValue: '员工评价',
			span: 24,
		},
		{
			label: '员工对本次服务老人的满意度',
			prop: 'serviceObjectStar',
			span: 12,
			custome: 'RateXing',
		},
		{
			label: '老人是否有其他服务需求',
			prop: 'existDemand',
			type: 'select',
			dicData: [
				{ label: '是', value: 1, type: 'success' },
				{ label: '否', value: 0, type: 'danger' },
			],
			span: 12,
		},
		{
			label: '其他服务需求说明',
			prop: 'demandExplain',
			span: 24,
		},
		{
			label: '备注说明',
			prop: 'remarks',
			span: 24,
		},
	],
}

export const api = {
	index: 'view_omReposOrder_page',
	export: 'view_omReposOrder_export',
	delete: 'view_omReposOrder_del',
	detail: 'view_omReposOrder_detail',
}
export const auth = {
	...api,
	mulitSet: 'mulitSet',
}
export const baseConfig = {
	pageName: '服务工单',
	dictcodes: [],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'orderNo',
	exportMqTopic: '/ning/export/',
	api,
	auth,
	menuBtn: [
		{
			icon: 'detail',
			label: '查看工单详情',
			type: 'primary',
			operate: 'detail',
			auth: auth.index,
			text: true,
			show: true,
		},
		{
			icon: 'delete',
			label: '删除',
			type: 'danger',
			operate: 'delete',
			auth: auth.delete,
			text: true,
			show: true,
		},
	],
	paramsObj: {
		hasOrderExtend: true,
	},
	saveFormate: async (form) => {
		return new Promise((resolve, reject) => {
			resolve({
				...form,
			})
		})
	},
	beforeOnLoadFormate: async (params) => {
		const areasObj: any = getAreaObj(params.areas, 'org')
		const queryObj = {
			...params,
			...areasObj,
			areas: undefined,
		}
		return Promise.resolve({
			...queryObj,
		})
	},
	onLoadFormate: async (arr) => {
		return new Promise((resolve, reject) => {
			const tempArr = arr.map((item) => {
				const middleServicePic = item.omReposOrderExtend?.middleServicePic
				if (middleServicePic) {
					if (typeof middleServicePic === 'string') {
						const tempArr = JSON.parse(middleServicePic)
						item.middleServicePicStr = tempArr.map((item) => item.imager)
					} else {
						item.middleServicePicStr = middleServicePic.map((item) => item.imager)
					}
				}
				return {
					...item,
				}
			})
			resolve(tempArr)
		})
	},
	dialogConfig: {
		width: '75%',
	},
	searchConfig,
	tableConfig,
	detailConfig,
}
